package com.hospital.demo.controller.jiajinpeng;

import com.hospital.demo.mapper.jiajinpeng.SurgeryMapper;
import com.hospital.demo.model.jiajinpeng.Surgery;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/sur")
@Api(tags={"手术安排"})
public class SurgeryCon {
    @Autowired
    private SurgeryMapper surgeryMapper;

    @ApiOperation(value = "获取全部信息", notes = "")
    @GetMapping("/findAll")
    private ResultVO findAll() {
        return ResultUtils.success(surgeryMapper.selectAll());
    }

    @ApiOperation(value = "通过医生姓名查询", notes = "")
    @GetMapping("/findBydoctor")
    private ResultVO finddoctor(@RequestParam(name = "sdoctor",defaultValue = "null")String sdoctor) {
        return ResultUtils.success(surgeryMapper.selectBydoctor(sdoctor));
    }

    @ApiOperation(value = "插入", notes = "")
    @PostMapping("/insert")
    private ResultVO insert(Surgery surgery) {
        return ResultUtils.success(surgeryMapper.insertSurgery(surgery));
    }

    @ApiOperation(value = "更新", notes = "")
    @PostMapping("/update")
    private ResultVO update(Surgery surgery) {
        return ResultUtils.success(surgeryMapper.updateSurgery(surgery));
    }

    @InitBinder
    private void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
}
